package com.situ.mall.product.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.situ.mall.common.util.Result;
import com.situ.mall.pojo.entity.product.Category;
import com.situ.mall.pojo.entity.product.Product;
import com.situ.mall.product.pojo.query.ProductQuery;
import com.situ.mall.product.pojo.vo.ProductVO;
import com.situ.mall.product.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 商品 前端控制器
 * </p>
 *
 * @author Z
 * @since 2024-10-09
 */
@RestController
@RequestMapping("/product")
public class ProductController {
    @Autowired
    IProductService productService;
    @RequestMapping("/list")
    public Result list(ProductQuery productQuery) {
        IPage<ProductVO> page = productService.list(productQuery);
        return Result.ok(page);
    }
    @RequestMapping("/add")
    public Result add(@RequestBody ProductVO productVO) {
        productService.save(productVO);
        return Result.ok();
    }
    @RequestMapping("/getById/{id}")
    public Result getById(@PathVariable Long id) {
        return Result.ok(productService.selectById(id));
    }
    @RequestMapping("/update")
    public Result update(@RequestBody ProductVO productVO) {
        productService.updateById(productVO);
        return Result.ok();
    }
    @RequestMapping("/selectPromoProduct")
    public Result selectPromoProduct(String categoryName) {
        System.out.println("categoryName:" + categoryName);
       return productService.selectPromoProduct(categoryName);
    }
    @PutMapping("/update")
    public Result update(@RequestBody Product product) {
        productService.update(product);
        return Result.ok("更新成功");
    }
}

